import { userOperationList, editUserOperationList } from '@/api/sys/user'
export default {
  data() {
    return {
      // EC全部公共字段
      cellIsShow: {
        IsRDFunction: true,
        IsCategory: true,
        IsItemNo: true,
        IsRiskImpact: true,
        IsGcmFunction: true,
        IsGcmOwner: true,
        IsGcmCostRemark: true,

        // ecdfc 添加的字段
        IsDeadline: true,
        IsPlan: true,
        IsFdDesign: true,
        IsOwner: true,
        IsInitialDate: true,
        IsCloseDate: true,
        IsSvtBomStatus: true,
        IsCostDown: true,
        IsApprvoal: true,
        IsRemark: true,
        IsOldPn: true,
        IsOldQty: true,
        IsNewPn: true,
        IsNewQty: true,
        Issubject: true,
        Iscommodity: true,
        IsassignedTime: true,
        IsisAssigned: true,
        IsisGcmCommit: true,
        IsisGcmReject: true
      }
    }
  },
  created() {
    this.getUserOperationList()
  },
  computed: {
    // 混入查找gcmOwner方法 减少代码量
    gcmOwnerById() {
      return gcmOwner => {
        if (gcmOwner && gcmOwner.length) {
          return this.$store.getters['user/getUserNameById'](gcmOwner)
        } else {
          return ''
        }
      }
    }
  },
  methods: {
    // 获取当前表格当前用户的操作习惯
    async getUserOperationList() {
      try {
        const { data: res } = await userOperationList({ pageId: this.pageId })
        if (res && res.jsonObjectOperation) {
          // this.cellIsShow = res.jsonObjectOperation
          // 深拷贝
          const data = res.jsonObjectOperation
          this.cellIsShow = JSON.parse(JSON.stringify(data))
        }
      } catch (error) {
        console.log(error)
      }
    },
    // 保存设置
    async saveOperationData(data) {
      try {
        await editUserOperationList({
          pageId: this.pageId,
          operationValue: JSON.stringify(data)
        })
        this.getUserOperationList()

        this.setDialogVisible = false
      } catch (error) {
        console.log(error)
      }
    }
  }
}
